import { computed,makeAutoObservable } from "mobx";
import { message } from 'antd';
import { AuthLoginDto,AuthRegisterDto } from "@/definition/dto/AuthDto";
import { API } from "@/request/api";
import Router from "../router";
class AuthStore{
    constructor(){
        makeAutoObservable(this,{
           
        })
    }
   async AuthLogin(config:AuthLoginDto){
    try{
        const {token} = await API.login(config);
        localStorage.setItem("Authorization",token.token);
        message.success("授权成功!");
    }catch{
        console.log("AuthLogin error");
    }
          
    };

   async AuthCode(email:string){    
    try{
        await API.code(email);
        message.success("发送验证码成功,请注意查收!");
    }catch{
        console.log("AuthCode error");
    } 
    };

   async AuthRegister(dto:AuthRegisterDto){
        await API.register(dto);
        message.success("入狱成功!");
        Router.navigate("/login");
    };

   

  
}
export  default AuthStore;
